package com.asa.group;

import java.util.ArrayList;
import java.util.List;

import com.asa.utils.Calculate;

public class Shuffle {

	
	/**
	 * m选其n进行组合
	 * @param m
	 * @param n
	 * @return
	 */
	public static List<int[]> Combination(int m,int n){
		
		return Calculate.zuhe_list(m, n);
	}
	
	
	
	/**
	 * 全排列，这里没有去重概念
	 * 可以得出结论后，自己去重
	 * @param intasa
	 * @return
	 */
	public static List<int[]> Permutation(int[] intasa){
		List<int[]> res = new ArrayList<int[]>();
		if (intasa==null||intasa.length==0) {
			return res;
		}
		
		process(intasa,0,res);
		
		return res;
		
		
	}

	
	
	private static void process(int[] intasa, int i, List<int[]> res) {
		// TODO Auto-generated method stub
		if (i==intasa.length) {
			
			int[] asb = new int[intasa.length];
			for (int j = 0; j < intasa.length; j++) {
				asb[j] = intasa[j];
			}
			
			res.add(asb);
		}
//		boolean[] visit = new boolean[26];//去重记录
		for (int j = i; j < intasa.length; j++) {
//			if (!visit[str[j]-'a']) {//去重的全排列
//				visit[str[j]-'a'] = true;
				swap(intasa,i,j);
				process(intasa, i+1, res);
				swap(intasa,i,j);
//			}
			
		}
		
	}

	private static void swap(int[] intasa, int i, int j) {
		// TODO Auto-generated method stub
		int asa = intasa[i];
		intasa[i] = intasa[j];
		intasa[j] = asa;
		
	}
	
	
	
	
	public static void main(String[] args) {
		
		int[] asa = {0,1,2};
		List<int[]> permutation = Permutation(asa);
		
		for (int i = 0; i < permutation.size(); i++) {
			int[] js = permutation.get(i);
			
			for (int j = 0; j < js.length; j++) {
				System.out.print(js[j]+"   ");

			}
			System.out.println();
		}
		
	}
	
}
